Skip to content

Add CreateTestClass/DeleteTestClass P/Invoke declarations to marshalling docs snippet - #54850

Merged
jkoritzinsky merged 3 commits into
mainfrom
copilot/add-examples-for-createtestclass-destroytestclass
Jul 22, 2026
Merged

Add CreateTestClass/DeleteTestClass P/Invoke declarations to marshalling docs snippet#54850
jkoritzinsky merged 3 commits into
mainfrom
copilot/add-examples-for-createtestclass-destroytestclass

Conversation

Copilot AI commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

CreateTestClass and DeleteTestClass were defined in PInvokeLib.h but absent from the managed P/Invoke declarations, leaving the documentation without coverage of how to marshal foreign heap-allocated C++ class pointers.

Changes

  • C# (NativeMethods.cs): Added both declarations using unsafe void* to represent the opaque CTestClass*:
[DllImport("PinvokeLib.dll", CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe void* CreateTestClass();

[DllImport("PinvokeLib.dll", CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe void DeleteTestClass(void* instance);
  • VB (NativeMethods.vb): Added equivalent declarations using IntPtr (VB has no void*):
<DllImport("PinvokeLib.dll", CallingConvention:=CallingConvention.Cdecl)>
Friend Shared Function CreateTestClass() As IntPtr
End Function

<DllImport("PinvokeLib.dll", CallingConvention:=CallingConvention.Cdecl)>
Friend Shared Sub DeleteTestClass(ByVal instance As IntPtr)
End Sub

Both declarations fall inside the existing <NativeMethods> snippet markers, so they surface automatically in the "Managed function prototypes" section of the published article.

Copilot AI review requested due to automatic review settings July 21, 2026 20:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Copilot AI changed the title [WIP] Add examples for CreateTestClass and DestroyTestClass usage Add CreateTestClass/DeleteTestClass P/Invoke declarations to marshalling docs snippet Jul 21, 2026
Copilot AI requested a review from jkoritzinsky July 21, 2026 20:06
@jkoritzinsky
jkoritzinsky marked this pull request as ready for review July 21, 2026 21:00
@jkoritzinsky
jkoritzinsky requested a review from a team as a code owner July 21, 2026 21:00
@jkoritzinsky

Copy link
Copy Markdown
Member

@copilot please add AllowUnsafeBlocks=true to the corresponding csproj for the C# code if it isn't already present

Copilot AI commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please add AllowUnsafeBlocks=true to the corresponding csproj for the C# code if it isn't already present

Added <AllowUnsafeBlocks>true</AllowUnsafeBlocks> to PInvokeLibManaged.csproj in commit 1e26bc2.

@jkoritzinsky
jkoritzinsky merged commit c12a559 into main Jul 22, 2026
11 checks passed
@jkoritzinsky
jkoritzinsky deleted the copilot/add-examples-for-createtestclass-destroytestclass branch July 22, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Marshalling Data with P/Invoke: missing examples using CreateTestClass/DestroyTestClass

4 participants